﻿using System;
using System.Web;
using System.Web.Mvc;
using Zinnia.Common.Untilty;

namespace CMS.Admin.Filters
{
    public class UserRegisterAttribute : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var key = "UserRegister" + httpContext.Request.UserHostAddress;
            var requestTime = LocalCacheHelper.Instance.GetCacheOjbect<int>(key);
            if (requestTime == 0)
            {
                LocalCacheHelper.Instance.Add(1, key, 10);
                return true;
            }
            return false;
        }
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            throw new Exception("请不要频繁提交请求！");
        }
    }
}